import React from "react";
import PropTypes from 'prop-types';
import {ShopService} from "../eosjs/EosService";
import {Badge, Button, Col, Descriptions, Input, message} from "antd";

class CreateStore extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            shopName: "",
            shopAddress: "",
            shopDesc: "",
            shopTag: "",
            shopPic: ""
        };
    }

    render() {
        return (
            <div>
                <Descriptions title="添加店铺" layout="vertical" bordered>
                    <Descriptions.Item label="店铺名称"><Input placeholder="请输入店铺名称" onChange={this.ShopNameChange}/></Descriptions.Item>
                    <Descriptions.Item label="店铺简介"><Input placeholder="请输入店铺简介" onChange={this.ShopDescChange}/></Descriptions.Item>
                    <Descriptions.Item label="店铺地址"><Input placeholder="请输入店铺地址" onChange={this.ShopAddressChange}/></Descriptions.Item>
                    <Descriptions.Item label="店铺标签"><Input placeholder="请输入店铺标签" onChange={this.ShopTagChange}/></Descriptions.Item>
                    <Descriptions.Item label="图片链接"><Input placeholder="请输入图片链接" onChange={this.ShopPicChange}/></Descriptions.Item>
                </Descriptions>
                <Button type={"primary"} onClick={this.createStore}>添加店铺</Button>
            </div>
        );
    }
    ShopTagChange = (e) => {
        this.setState({shopTag: e.target.value})
    }
    ShopNameChange = (e) => {
        this.setState({shopName: e.target.value})
    }
    ShopDescChange = (e) => {
        this.setState({shopDesc: e.target.value})
    }
    ShopPicChange = (e) => {
        this.setState({shopPic: e.target.value})
    }
    ShopAddressChange = (e) => {
        this.setState({shopAddress: e.target.value})
    }
    createStore = () => {
        if(this.state.shopName === "" || this.state.shopPic === "" || this.state.shopDesc === "" || this.state.shopTag === "" || this.state.shopAddress === ""){
            message.error("店铺创建失败，字段不允许为空！");
            return ;
        }
        ShopService.insertShop(this.state.shopName, this.state.shopPic, this.state.shopDesc, this.state.shopTag, this.state.shopAddress).then(res => {
            if(res.status === true){
                message.success("店铺创建成功！");
                this.props.history.push("/myStoreList");
            }
            else{
                message.error("店铺创建失败！");
            }
        });
    }
}

CreateStore.propTypes = {};

export default CreateStore;